home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992…ugust: Hack to the Future / ADC Developer CD (1992-08) (''Hack To The Future'')_iso / Dev.CD 199208.iso / Periodicals / develop / develop 11 code / Graphical Truffles / Blasto.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-15  |  3.4 KB  |  128 lines  |  [TEXT/MPS ]

  1. /*
  2.     Blasto
  3.     A small program that blasts an 8 bit color icon to the screen.
  4.     3-6-92         By Brigham Stevens
  5.                 Apple Developer Technical Support
  6.     3-13-92    - BRS - Uh Oh, it's Friday the 13th
  7.                 Cleaned up & commented code here and there.
  8.     4-13-92 - BRS - changed icon to be self-erasing
  9.                 Made code somewhat better by changing names and stuff.
  10.                 Added comments
  11.     4-24-93 - BRS - Added ifdefs around timing code, changed names again.
  12. */
  13.  
  14. #include <OSUtils.h>
  15. #include <Windows.h>
  16. #include <QDOffscreen.h>
  17. #include <Retrace.h>
  18. #include <Memory.h>
  19. #include <Resources.h>
  20. #include <Events.h>
  21. #include <Menus.h>
  22. #include "DirectScreen.h"
  23.  
  24. void InitToolBox(short numMoreMasters);
  25.  
  26. /* Amount to move icons these need to be around 1 or 2    */
  27. /*    or our icon will not be self erasing */
  28. #define ROW_OFF    1
  29. #define COL_OFF 1
  30.  
  31. #define MAX_SECONDS 100
  32.  
  33. void ShowResult(long frameCount);
  34. long AverageTable(long *tab, short count);
  35.  
  36. void main()
  37. {
  38.     WindowPtr        directWindow;
  39.     GrafPort        killMenuBar;
  40.     Rect            screenRect;
  41.     GDHandle        mainScreen;
  42.     PixMapHandle    mainscreenPixMap;
  43.     Handle            colorIconHandle;
  44.     Point            plotLocation;
  45.     short            vDelta = ROW_OFF;
  46.     short            hDelta = COL_OFF;
  47.     long            frameCount;
  48.     long            *ticks = (long*)0x16A;
  49.     long            beforeTicks;    
  50.     long            tickTable[MAX_SECONDS];
  51.     short            tickIndex = 0;
  52.  
  53.     /* Standard Witch Chant enclosed... */
  54.     InitToolBox(4);        /* 4 calls to MoreMasters */
  55.  
  56.     /* get a handle to the color icon we are drawing */
  57.     colorIconHandle = GetResource('icl8',128);
  58.     if(!colorIconHandle) {
  59.         SysBeep(5);
  60.         DebugStr("\pBuild problems: 'icl8' not loaded.");
  61.         return;
  62.     }
  63.  
  64.     /* cover up the part of the screen we are writing on */
  65.     /* with a window, so other apps will not mess with our */
  66.     /* animation via update events in the background */
  67.     screenRect = qd.screenBits.bounds;
  68.     directWindow = NewWindow(nil,&screenRect,nil,true,plainDBox,nil,false,0L);
  69.  
  70.     /* This covers up the menu bar */
  71.     /* and fills the screen with white */
  72.     OpenPort((GrafPtr)&killMenuBar);
  73.     EraseRect(&killMenuBar.portRect);
  74.     
  75.     /* get the main screen's Pix map */
  76.     /* Which this program expects to be 8 bits deep */
  77.     mainScreen = GetMainDevice();
  78.     mainscreenPixMap = (**mainScreen).gdPMap;
  79.             
  80.     /* Set up a safe rectangle for bouncing off the screen */
  81.     screenRect.top = 4;
  82.     screenRect.left = 4;
  83.     screenRect.bottom -= 32;
  84.     screenRect.right -= 32;
  85.  
  86.  
  87.     /* loop until the mouse is clicked */
  88.     /* drawing and moving the color icon */
  89.  
  90.     
  91.     for(tickIndex = 0; tickIndex < MAX_SECONDS; tickIndex++) {
  92.         /* This is where to start drawing the color icon*/
  93.         plotLocation.h = 100;
  94.         plotLocation.v = 100;
  95.         frameCount = 0;
  96.         beforeTicks = *ticks;
  97.         while((*ticks - beforeTicks) < 60) {
  98.     
  99.             /* update the location of the icon */
  100.             plotLocation.v += vDelta;
  101.             plotLocation.h += hDelta;
  102.             /* This forces us to stay on the screen and prevent bus errors */
  103.             if(!PtInRect(plotLocation,&screenRect)) {
  104.                 vDelta = -vDelta;    /* swap the deltas to bounce of corner */
  105.                 hDelta = -hDelta;
  106.             }
  107.     
  108.             /* draw the icon */
  109.             
  110.             DirectPlotColorIcon((long *)*colorIconHandle, 
  111.                         mainscreenPixMap, plotLocation.v, plotLocation.h);
  112.             frameCount++;
  113.             /* this was not part of the timing code, but */
  114.             /* I want to be able to bail out early */
  115.             if(Button()) ExitToShell();
  116.         }
  117.         tickTable[tickIndex] = frameCount;
  118.     }
  119.     
  120.     /* show the average number of frames per second for MAX_SECONDS seconds */
  121.     
  122.     ShowResult( AverageTable(tickTable,MAX_SECONDS) );
  123.         
  124.     CloseWindow(directWindow);
  125.     ClosePort((GrafPtr)&killMenuBar);
  126.     DrawMenuBar();
  127.     
  128. }